package com.szrt.oa.role.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.szrt.oa.menu.dao.MenuDao;
import com.szrt.oa.menu.entity.MenuEntity;
import com.szrt.oa.user.dao.UserDao;
import com.szrt.oa.user.entity.UserEntity;
import com.szrt.oa.user.service.UserService;

@Service
public class UserServiceImpl implements UserService  {
	
	@Autowired
	private UserDao userdao;
	@Autowired
	private MenuDao menudao;
	
	
	private Map<String, Object> map=null;
	
	
	@Transactional(readOnly=true)
	@Override
	public Map<String, Object> findMenuByid(UserEntity entity) {
		
		try {
			UserEntity userEntity = userdao.findById(entity.getPhone());
			Integer id = userEntity.getId();
			
			//获得权限list
			List<MenuEntity> menuList = menudao.findMenuByUserId(id);
			map=new HashMap<String, Object>();
			
			//成功返回
			map.put("coode",200);
			map.put("menuList", menuList);
			
		} catch (Exception e) {
			
			//失败返回
			map.put("coode",500);
			map.put("menuList", "null");
			e.printStackTrace();
		}
		return map;
	}



	@Transactional(readOnly=false)
	@Override
	public Map<String, Object> login(UserEntity entity) {
//		userdao= session.getMapper(UserDao.class);
		
		try {
			UserEntity userLogin = userdao.login(entity);
			map=new HashMap<String,Object>();
			
			//成功返回
			map.put("coode",200);
			map.put("userLogin",userLogin);
			
			
			
		} catch (Exception e) {
			//失败返回
			map.put("coode",200);
			map.put("userLogin", "null");
			e.printStackTrace();
		}
		
		return map;
	}
	

}
